package com.ly.hotel.spainterface.jg.utils;

import android.os.Handler;
import android.os.Message;

import com.ly.hotel.common.MyApplication;
import com.ly.hotel.spainterface.jg.bean.HostAndTvInfo;
import com.ly.hotel.spainterface.jg.bean.OnGetHostAndTvInfoListener;

/**
 * Created by ThinkPad on 2018/3/12.
 */

public class GetMachineInfoUtils {

    private OnGetHostAndTvInfoListener onGetHostAndTvInfoListener;

    public void setOnGetHostAndTvInfoListener(OnGetHostAndTvInfoListener onGetHostAndTvInfoListener) {
        this.onGetHostAndTvInfoListener = onGetHostAndTvInfoListener;
    }

    private  Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case 1:
                    HostAndTvInfo hostAndTvInfo = (HostAndTvInfo) msg.obj;
                    String serverIP = hostAndTvInfo.getServerIP();
                    String serverPORT = hostAndTvInfo.getServerPORT();
                    String mac = hostAndTvInfo.getMac();
                    String categoryName = hostAndTvInfo.getCategoryName();
                    String tvName = hostAndTvInfo.getTvName();
                    onGetHostAndTvInfoListener.getHostAndTvInfo(serverIP,serverPORT,mac,categoryName,tvName);
                    break;

                case 2:

                    break;

                default:
                    break;
            }
        }
    };

    public void getHostAndTvInof(){
        new Thread(){
            @Override
            public void run() {
                String str = MyApplication.getHostIpAndPort().replace(":", ",");
                String mac = MyApplication.getMAC();
                String categoryName =MyApplication.getDeviceInfo().getCategoryName();
                String tvName = MyApplication.getDeviceInfo().getName();
                Message message = new Message();
                message.what = 1;
                HostAndTvInfo hostAndTvInfo = new HostAndTvInfo();
                if(str != null){
                    String[] host = str.split(",");
                    hostAndTvInfo.setServerIP(host[0]);
                    hostAndTvInfo.setServerPORT(host[1]);
                    hostAndTvInfo.setMac(mac);
                    hostAndTvInfo.setCategoryName(categoryName);
                    hostAndTvInfo.setTvName(tvName);
                }
                message.obj = hostAndTvInfo;
                handler.sendMessage(message);
            }
        }.start();
    }

}
